<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>交流群汇总 - VR俱乐部</title>
    <!-- 引入Bootstrap和Font Awesome -->
    <link rel="stylesheet" href="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/bootstrap/5.2.3/css/bootstrap.min.css">
    <link href="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    <style>
      body {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        margin: 0;
      }

      .content {
        flex: 1;
        padding-bottom: 60px; /* 为页脚腾出空间 */
      }

      footer {
        background-color: #b81414;
        color: #fff;
        text-align: center;
        padding: 15px 0;
      }
      
      .logo-img {
          height: 20px;
          vertical-align: middle; /* 垂直居中对齐，使图片与文字对齐 */
      }

      /* 样式部分 */
      .qq-groups-container {
        background-color: #f8f9fa;
        min-height: 100vh;
        padding-bottom: 50px;
      }

      .hero-banner {
        position: relative;
        height: 200px;
        overflow: hidden;
        margin-bottom: 30px;
        background-color: #d91111;
      }

      .hero-overlay {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        text-align: center;
        color: white;
        width: 100%;
        padding: 0 15px;
      }

      .hero-overlay h1 {
        font-size: 2.5rem;
        font-weight: 700;
        margin-bottom: 15px;
        text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
      }

      .hero-overlay p {
        font-size: 1.2rem;
        text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
      }

      .search-filter {
        background-color: white;
        border-radius: 10px;
        padding: 20px;
        margin-bottom: 30px;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
      }

      .search-box {
        position: relative;
        margin-bottom: 20px;
      }

      .search-box i {
        position: absolute;
        right: 15px;
        top: 12px;
        color: #7f8c8d;
      }

      .search-box input {
        padding-right: 40px;
        border-radius: 50px;
      }

      .filter-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
      }

      .filter-tags button {
        border-radius: 50px;
        padding: 5px 15px;
      }

      .filter-tags button.active {
        background-color: #3498db;
        color: white;
      }

      .category-title {
        font-size: 1.5rem;
        margin: 30px 0 20px;
        color: #2c3e50;
        display: flex;
        align-items: center;
      }

      .category-title i {
        margin-right: 10px;
        color: #3498db;
      }

      .category-title .badge {
        margin-left: 10px;
        font-size: 0.8rem;
        padding: 5px 10px;
        color: #fff;
      }

      .group-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
        gap: 20px;
      }

      .group-card {
        background-color: white;
        border-radius: 10px;
        padding: 20px;
        display: flex;
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        transition: all 0.3s;
      }

      .group-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
      }

      .group-avatar {
        width: 60px;
        height: 60px;
        margin-right: 15px;
        flex-shrink: 0;
      }

      .group-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 8px;
      }

      .group-info {
        flex: 1;
      }

      .group-info h3 {
        font-size: 1.1rem;
        margin-bottom: 5px;
        color: #2c3e50;
      }

      .group-id {
        font-size: 0.8rem;
        color: #7f8c8d;
        margin-bottom: 0px;
      }

      .group-desc {
        word-break: break-all;
        font-size: 0.9rem;
        color: #7f8c8d;
        margin-bottom: 10px;
        display: -webkit-box;
        line-clamp: 3;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
      }

      .group-meta {
        font-size: 0.8rem;
        color: #7f8c8d;
      }

      .group-meta span {
        margin-right: 15px;
      }

      .group-meta i {
        margin-right: 5px;
        color: #3498db;
      }

      .group-actions {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-left: 15px;
      }

      .btn-join {
        margin-bottom: 10px;
        padding: 5px 15px;
        font-size: 0.9rem;
        border-radius: 5px;
      }

      .btn-copy {
        padding: 5px 15px;
        font-size: 0.9rem;
        border-radius: 5px;
      }

      .no-results {
        text-align: center;
        padding: 50px 0;
        color: #7f8c8d;
      }

      .no-results i {
        color: #3498db;
        margin-bottom: 20px;
      }

      .no-results h3 {
        font-size: 1.5rem;
        margin-bottom: 10px;
      }

      .copy-notification {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        background-color: #2ecc71;
        color: white;
        padding: 10px 20px;
        border-radius: 5px;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
        animation: fadeInOut 3s ease-in-out;
        display: none;
      }

      @keyframes fadeInOut {
        0% { opacity: 0; }
        10% { opacity: 1; }
        90% { opacity: 1; }
        100% { opacity: 0; }
      }

      @media (max-width: 768px) {
        .hero-overlay h1 {
          font-size: 2rem;
        }
        
        .hero-overlay p {
          font-size: 1rem;
        }
        
        .group-list {
          grid-template-columns: 1fr;
        }
        
        .group-card {
          flex-direction: column;
          align-items: center;
          text-align: center;
        }
        
        .group-avatar {
          margin-right: 0;
          margin-bottom: 15px;
        }
        
        .group-actions {
          flex-direction: row;
          margin-left: 0;
          margin-top: 15px;
        }
        
        .btn-join, .btn-copy {
          margin-right: 10px;
          margin-bottom: 0;
        }
        
        /* 移动端群信息维护样式优化 */
        .form-prompt {
          width: calc(100% - 30px);
          margin-left: 15px;
          margin-right: 15px;
          max-width: none;
          padding: 15px;
        }
      }

      .view-all-events {
        color: #d91111;
        font-weight: 600;
        text-decoration: none;
        display: inline-block;
        transition: all 0.3s;
      }

      .view-all-events:hover {
        color: #b81414;
        transform: translateX(-5px);
      }

      .view-all-events i {
        margin-right: 5px;
        transition: all 0.3s;
      }

      .view-all-events:hover i {
        transform: translateX(-5px);
      }

      /* 群信息维护样式 */
      .form-prompt {
        background-color: #fef1f1;
        border: 1px solid #f7d0d0;
        border-radius: 10px;
        padding: 20px;
        margin: 40px auto 20px;
        max-width: 600px;
        text-align: center;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
        transition: all 0.3s ease;
      }

      .form-prompt:hover {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        transform: translateY(-2px);
      }

      .form-prompt p {
        font-size: 1rem;
        color: #2c3e50;
        margin-bottom: 10px;
        margin-top: 10px;
      }

      .form-prompt .text-muted {
        color: #95a5a6;
        margin: 0 8px;
      }

      .link-underline {
        color: #d91111;
        font-weight: 600;
        text-decoration: none;
        position: relative;
        padding-bottom: 2px;
        transition: all 0.3s;
      }

      .link-underline::after {
        content: '';
        position: absolute;
        width: 0;
        height: 2px;
        bottom: 0;
        left: 0;
        background-color: #d91111;
        transition: width 0.3s ease;
      }

      .link-underline:hover {
        color: #b81414;
      }

      .link-underline:hover::after {
        width: 100%;
      }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #b81414;">
        <div class="container">
            <a class="navbar-brand" href="/">VR俱乐部</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="about.html">社团简介</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="history.html">发展历程</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="cgzs.html">成果展示</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="hdyx.html">活动影像</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" target="_blank" href="https://mp.weixin.qq.com/mp/appmsgalbum?action=getalbum&__biz=MzIzMDU3NzQ1MQ==&scene=1&album_id=2927847544494440450&count=3#wechat_redirect">使用攻略</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="dh.html">网址导航</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="qq-groups.html">交流群汇总</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" target="_blank" href="https://wiki.ecustvr.top/">Wiki</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" target="_blank" href="http://git.ecustvr.top/">Git</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="qq-groups-container">
      <!-- 顶部横幅 -->
      <div class="hero-banner">
        <div class="hero-overlay">
          <h1>交流群汇总</h1>
          <p>加入兴趣社群 · 结识同好伙伴 · 获取最新资讯</p>
        </div>
      </div>

      <div class="container">
        <!-- 搜索和筛选 -->
        <div class="search-filter">
          <div class="search-box">
            <input 
              type="text" 
              id="searchInput"
              placeholder="搜索群名称或描述..."
              class="form-control"
            >
            <i class="fas fa-search"></i>
          </div>
          <div class="filter-tags" id="filterTags">
            <!-- 分类标签将通过JavaScript动态生成 -->
          </div>
        </div>

        <!-- 加载状态 -->
        <div id="loadingState" class="text-center py-5">
          <div class="spinner-border text-primary" role="status"></div>
          <p class="mt-3">正在加载群组信息...</p>
        </div>

        <!-- 群组列表 -->
        <div id="groupsSection" class="groups-section" style="display: none;">
          <!-- 分类和群组将通过JavaScript动态生成 -->
        </div>

        <!-- 无结果提示 -->
        <div id="noResults" class="no-results" style="display: none;">
          <i class="fas fa-search fa-3x"></i>
          <h3>未找到匹配的交流群</h3>
          <p>尝试调整搜索关键词或筛选条件</p>
        </div>
      </div>

      <!-- 返回链接 -->
      <div class="text-center mt-5">
        <a href="/" class="view-all-events" id="backLink">
          <i class="fas fa-chevron-left"></i> 返回首页
        </a>
      </div>
      
      <div class="form-prompt">
        <p>群信息维护 <span class="text-muted">|</span> 请通过官方表单提交更新</p>
        <a href="https://ecustcic.feishu.cn/share/base/form/shrcn5SJVIvKbkfDZxQsn0djtng" 
          target="_blank" 
          class="link-underline">
          立即填写表单 →
        </a>
        <p>本页信息由 <a href="https://www.ecustcic.com/" target="_blank" class="link-underline">CIC计算机信息交流协会</a> 提供</p>
      </div>
          
      <!-- 复制成功提示 -->
      <div id="copyNotification" class="copy-notification">
        已复制群号 <span id="copiedNumber"></span> 到剪贴板
      </div>
    </div>

    <footer>
        <script type="text/javascript">
            var currentYear = new Date().getFullYear();
            var hostname = window.location.hostname;
            var footerContent = '&copy; ' + currentYear + ' VR俱乐部 ';
            
            // 只在www.ecustvr.top域名下显示备案号以及赞助信息
            if (hostname === 'www.ecustvr.top') {
                footerContent += '<a class="nav-link" href="https://beian.miit.gov.cn/" target="_blank">苏ICP备2023000758号-2</a> <a class="nav-link" target="_blank" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=31012102000135" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;"><img src="https://beian.mps.gov.cn/img/ghs.png" style="float:left;"/>沪公网安备31012102000135号</p></a>';
                footerContent += '<a class="nav-link" href="https://edgeone.ai/zh?from=github" target="_blank">本站CDN加速及安全防护由 <img src="https://edgeone.ai/media/34fe3a45-492d-4ea4-ae5d-ea1087ca7b4b.png" alt="亚洲最佳CDN、边缘和安全解决方案 - Tencent EdgeOne" class="logo-img img-fluid"> 赞助</a>';
            }
            
            document.write(footerContent);
        </script>
    </footer>
    <script>
      // 全局变量
      const state = {
        searchQuery: '',
        selectedCategories: [],
        showCopySuccess: false,
        copiedGroupNumber: '',
        loading: true,
        categories: [
          // { id: 'study', name: '学习交流', icon: 'fas fa-book' },
          { id: 'social', name: '友好社团', icon: 'fas fa-users' },
          { id: 'tech', name: '技术讨论', icon: 'fas fa-code' },
          { id: 'area', name: '区域性交流群', icon: 'fas fa-globe' },
          { id: 'school', name: '学院群', icon: 'fas fa-university' },
          { id: 'game', name: '休闲娱乐', icon: 'fas fa-gamepad' }
        ],
        groups: [],
        appId: 'cli_a8f1d48265fc500e',
        appSecret: 'u2NfRSgPlrI4KUhba3389eyj3LSa4aGR',
        accessToken: null
      };

      // DOM元素
      const elements = {
        searchInput: document.getElementById('searchInput'),
        filterTags: document.getElementById('filterTags'),
        loadingState: document.getElementById('loadingState'),
        groupsSection: document.getElementById('groupsSection'),
        noResults: document.getElementById('noResults'),
        copyNotification: document.getElementById('copyNotification'),
        copiedNumber: document.getElementById('copiedNumber'),
        backLink: document.getElementById('backLink')
      };

      // 初始化函数
      function init() {
        // 渲染分类标签
        renderCategoryTags();
        
        // 添加事件监听器
        addEventListeners();
        
        // 获取数据
        fetchGroupsFromFeishu();
      }

      // 渲染分类标签
      function renderCategoryTags() {
        state.categories.forEach(category => {
          const button = document.createElement('button');
          button.className = 'btn btn-sm btn-outline-primary';
          button.dataset.categoryId = category.id;
          button.textContent = category.name;
          button.addEventListener('click', () => toggleCategory(category.id));
          elements.filterTags.appendChild(button);
        });
      }

      // 添加事件监听器
      function addEventListeners() {
        // 搜索输入框
        elements.searchInput.addEventListener('input', () => {
          state.searchQuery = elements.searchInput.value;
          renderGroups();
        });
      }

      // 切换分类选择
      function toggleCategory(categoryId) {
        const index = state.selectedCategories.indexOf(categoryId);
        if (index === -1) {
          state.selectedCategories.push(categoryId);
        } else {
          state.selectedCategories.splice(index, 1);
        }
        
        // 更新UI
        updateCategoryButtons();
        renderGroups();
      }

      // 更新分类按钮状态
      function updateCategoryButtons() {
        const buttons = elements.filterTags.querySelectorAll('button');
        buttons.forEach(button => {
          const categoryId = button.dataset.categoryId;
          if (state.selectedCategories.includes(categoryId)) {
            button.classList.add('active');
          } else {
            button.classList.remove('active');
          }
        });
      }

      // 获取飞书访问令牌
      async function getTenantAccessToken() {
        try {
          const response = await fetch('https://feishuapi.bestzyq.cn/open-apis/auth/v3/tenant_access_token/internal', {
            method: 'POST',
            headers: {
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({
              app_id: state.appId,
              app_secret: state.appSecret
            })
          });
          const data = await response.json();
          if (data.code === 0) {
            state.accessToken = data.tenant_access_token;
            return data.tenant_access_token;
          } else {
            console.error('获取飞书访问令牌失败:', data);
            return null;
          }
        } catch (error) {
          console.error('获取飞书访问令牌出错:', error);
          return null;
        }
      }
      
      // 从飞书获取群组数据
      async function fetchGroupsFromFeishu() {
        state.loading = true;
        let allGroups = [];
        let pageToken = null;
        let hasMore = true;
        
        try {
          // 获取访问令牌
          const token = await getTenantAccessToken();
          if (!token) {
            state.loading = false;
            showError('获取飞书访问令牌失败');
            return;
          }
          
          // 循环获取所有页的数据
          while (hasMore) {
            // 构建URL，将page_token作为查询参数添加
            let url = 'https://feishuapi.bestzyq.cn/open-apis/bitable/v1/apps/Y9HBbtQoxawALxs3XK8cOY9pn8g/tables/tblVq51wR2ZPVax4/records/search?page_size=100';
            if (pageToken) {
              url += `&page_token=${pageToken}`;
            }
            
            // 获取飞书表格数据
            const response = await fetch(url, {
              method: 'POST',
              headers: {
                'Authorization': `Bearer ${token}`,
                'Content-Type': 'application/json'
              },
              body: JSON.stringify({
                "sort": [
                  {
                    "field_name": "类别",
                    "desc": false
                  }
                ],
                "filter": {
                  "conjunction": "and",
                  "conditions": [
                    {
                      "field_name": "是否可信",
                      "operator": "is",
                      "value": ["true"]
                    }
                  ]
                }
              })
            });
            
            const data = await response.json();
            if (data.code === 0) {
              const pageGroups = data.data.items.map(item => {
                // 将飞书数据映射到我们需要的格式
                const groupId = item.fields['QQ群号'];
                const url = (item.fields['加群链接'] && item.fields['加群链接'].link) || null;
                
                // 处理描述字段，现在是一个对象数组
                let description = '暂无描述';
                if (item.fields['描述'] && Array.isArray(item.fields['描述']) && item.fields['描述'].length > 0) {
                  // 将所有文本片段连接起来
                  description = item.fields['描述']
                    .filter(desc => desc.type === 'text')
                    .map(desc => desc.text)
                    .join('');
                }
                
                // 处理群名称字段
                let groupName = `群组(${groupId})`;  // 默认名称
                let apiSuccess = false;
                
                if (item.fields['群名称'] && Array.isArray(item.fields['群名称']) && item.fields['群名称'].length > 0) {
                  const nameText = item.fields['群名称']
                    .filter(name => name.type === 'text')
                    .map(name => name.text)
                    .join('');
                  
                  if (nameText) {
                    groupName = nameText;
                    apiSuccess = true;
                  }
                }
                
                // 处理群人数字段
                let memberCount = 0;
                let maxMemberCount = 0;
                
                if (item.fields['群人数'] && Array.isArray(item.fields['群人数']) && item.fields['群人数'].length > 0) {
                  const countText = item.fields['群人数']
                    .filter(count => count.type === 'text')
                    .map(count => count.text)
                    .join('');
                  
                  if (countText) {
                    // 尝试解析格式如 "1773 / 2000" 的字符串
                    const countMatch = countText.match(/\s*(\d+)\s*\/\s*(\d+)\s*/);
                    if (countMatch) {
                      memberCount = parseInt(countMatch[1], 10);
                      maxMemberCount = parseInt(countMatch[2], 10);
                      apiSuccess = apiSuccess && true;  // 只有当群名称也存在时才为true
                    } else {
                      apiSuccess = false;
                    }
                  } else {
                    apiSuccess = false;
                  }
                } else {
                  apiSuccess = false;
                }
                
                return {
                  group_id: String(groupId), // 确保群号是字符串
                  group_name: groupName,
                  description: description,
                  category: mapCategoryFromFeishu(item.fields['类别']),
                  url: url,
                  api_success: apiSuccess,
                  member_count: memberCount,
                  max_member_count: maxMemberCount
                };
              });
              
              // 将当前页的群组添加到总列表中
              allGroups = [...allGroups, ...pageGroups];
              
              // 检查是否有更多页
              hasMore = data.data.has_more;
              pageToken = data.data.page_token;
              
              // 如果没有更多数据或没有返回页码令牌，则停止循环
              if (!hasMore || !pageToken) {
                break;
              }
            } else {
              console.error('获取飞书数据失败:', data);
              hasMore = false;
            }
          }
          
          state.groups = allGroups;
          state.loading = false;
          
          // 更新UI
          renderGroups();
        } catch (error) {
          console.error('获取群组信息出错:', error);
          state.loading = false;
          showError('获取群组信息失败');
        }
      }
      
      // 将飞书类别映射到我们的类别ID
      function mapCategoryFromFeishu(feishuCategory) {
        const categoryMap = {
          '学习交流': 'social',
          '休闲娱乐': 'game',
          '技术讨论': 'tech',
          '友好社团': 'social',
          '区域性交流群': 'area',
          '学院群': 'school'
        };
        
        return categoryMap[feishuCategory] || 'social'; // 默认为social类别
      }
      
      // 获取筛选后的群组
      function getFilteredGroups() {
        return state.groups.filter(group => {
          const searchMatch = 
            group.group_name.toLowerCase().includes(state.searchQuery.toLowerCase()) ||
            group.description.toLowerCase().includes(state.searchQuery.toLowerCase());
          
          const categoryMatch = 
            state.selectedCategories.length === 0 || 
            state.selectedCategories.includes(group.category);
          
          return searchMatch && categoryMatch;
        });
      }
      
      // 获取筛选后的分类
      function getFilteredCategories() {
        const filteredGroups = getFilteredGroups();
        return state.categories.filter(cat => 
          filteredGroups.some(group => group.category === cat.id)
        );
      }
      
      // 获取特定分类的群组
      function getGroupsByCategory(categoryId) {
        return getFilteredGroups().filter(group => group.category === categoryId);
      }
      
      // 获取特定分类的群组数量
      function getGroupCount(categoryId) {
        return getGroupsByCategory(categoryId).length;
      }
      
      // 复制群号
      function copyGroupNumber(number) {
        navigator.clipboard.writeText(number);
        state.copiedGroupNumber = number;
        showCopyNotification(number);
      }
      
      // 显示复制成功提示
      function showCopyNotification(number) {
        elements.copiedNumber.textContent = number;
        elements.copyNotification.style.display = 'block';
        elements.copyNotification.style.animation = 'none';
        void elements.copyNotification.offsetWidth; // 触发重绘
        elements.copyNotification.style.animation = 'fadeInOut 3s ease-in-out';
        
        setTimeout(() => {
          elements.copyNotification.style.display = 'none';
        }, 3000);
      }
      
      // 显示错误信息
      function showError(message) {
        elements.loadingState.innerHTML = `
          <div class="alert alert-danger" role="alert">
            <i class="fas fa-exclamation-triangle"></i> ${message}
          </div>
        `;
      }
      
      // 渲染群组列表
      function renderGroups() {
        const filteredGroups = getFilteredGroups();
        const filteredCategories = getFilteredCategories();
        
        // 更新UI状态
        elements.loadingState.style.display = 'none';
        
        if (filteredGroups.length === 0) {
          elements.groupsSection.style.display = 'none';
          elements.noResults.style.display = 'block';
        } else {
          elements.groupsSection.style.display = 'block';
          elements.noResults.style.display = 'none';
          
          // 清空现有内容
          elements.groupsSection.innerHTML = '';
          
          // 按分类渲染群组
          filteredCategories.forEach(category => {
            const categoryGroups = getGroupsByCategory(category.id);
            if (categoryGroups.length === 0) return;
            
            const categoryElement = document.createElement('div');
            categoryElement.className = 'category-group';
            
            // 分类标题
            const titleElement = document.createElement('h2');
            titleElement.className = 'category-title';
            titleElement.innerHTML = `
              <i class="${category.icon}"></i>
              ${category.name}
              <span class="badge bg-primary">${categoryGroups.length}</span>
            `;
            categoryElement.appendChild(titleElement);
            
            // 群组列表
            const groupListElement = document.createElement('div');
            groupListElement.className = 'group-list';
            
            // 添加每个群组卡片
            categoryGroups.forEach(group => {
              const groupCard = document.createElement('div');
              groupCard.className = 'group-card';
              
              groupCard.innerHTML = `
                <div class="group-avatar">
                  <img src="https://p.qlogo.cn/gh/${group.group_id}/${group.group_id}/640" alt="${group.description}" onerror="this.src='https://qzonestyle.gtimg.cn/qzone/qzact/act/external/tiqq/logo.png'">
                </div>
                <div class="group-info">
                  <h3>
                    ${group.group_name}
                    ${!group.api_success ? '<span class="badge bg-warning">信息不完整</span>' : ''}
                  </h3>
                  <p class="group-id">${group.group_id}</p>
                  <p class="group-desc">${group.description}</p>
                  ${group.api_success ? `
                  <div class="group-meta">
                    <span><i class="fas fa-users"></i> ${group.member_count}人/${group.max_member_count}人</span>
                  </div>
                  ` : ''}
                </div>
                <div class="group-actions">
                  ${group.url ? `
                  <a href="${group.url}" target="_blank" class="btn btn-primary btn-join">
                    <i class="fab fa-qq"></i> 加入群聊
                  </a>
                  ` : ''}
                  <button class="btn btn-outline-secondary btn-copy" data-group-id="${group.group_id}">
                    <i class="far fa-copy"></i> 复制群号
                  </button>
                </div>
              `;
              
              // 添加复制群号事件监听器
              groupListElement.appendChild(groupCard);
            });
            
            categoryElement.appendChild(groupListElement);
            elements.groupsSection.appendChild(categoryElement);
          });
          
          // 添加复制群号按钮的事件监听器
          document.querySelectorAll('.btn-copy').forEach(button => {
            button.addEventListener('click', () => {
              const groupId = button.dataset.groupId;
              copyGroupNumber(groupId);
            });
          });
        }
      }
      
      // 页面加载完成后初始化
      document.addEventListener('DOMContentLoaded', init);
    </script>
    <script src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/popper.js/2.10.2/umd/popper.min.js"></script>
    <script src="https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/bootstrap/5.2.3/js/bootstrap.min.js"></script>
</body>
</html>